/**
 * 合同登记表查询
 * @author miaoyl
 * @date 2019/12/17
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        table,
        element,
        vueData = {

        },
        table_where = {

        },
        cols = [[
            {field: 'ROW_ID', width: 60, title: '序号', fixed: 'left'}
            , {field: 'GWCA003', width: 60, title: '招标', fixed: 'left',filterDatas: app.datas_('sys_n_y')}
            , {field: 'GWCA039', width: 120, title: '中标通知书'}
            , {field: 'GWCA037', width: 120, title: '归档时间', sort: true}
            , {field: 'GWCA038', width: 120, title: '合同回笼份数',sort: true}
            , {field: 'GWCAMLEGAL_NAME', width: 160, title: '签订单位'}
            , {field: 'GWCA005', width: 100, title: '合同编号',sort: true,search: 'default', searchOpts: {icon: true,readonly:true}}
            , {field: 'GWCA036', width: 100, title: '签订日期',sort: true}
            , {field: 'GWCA002', width: 100, title: '订单类型',sort: true, filterDatas: app.datas_('crm_gwci001_gwca002'),
                search: 'default',searchOpts: {type:'select'}
            }
            , {field: 'GWAK009', width: 100, title: '客户类型', filterDatas: app.datas_('crm_gwai300_gwak009')}
            , {field: 'GWCA006_NAME', width: 160, title: '客户单位'}
            , {field: 'GWAHL003', width: 120, title: '产品大类'}
            , {field: 'GWAOL003', width: 120, title: '车辆类型'}
            , {field: 'GWCB002', width: 160, title: '型号', sort: true}
            , {field: 'GWCB005_NAME', width: 80, title: '单位'}
            , {field: 'GWCB006', width: 100, title: '数量'}
            , {field: 'GWCB008', width: 100, title: '单价(元)'}
            , {field: 'GWCB010', width: 100, title: '总价(元)'}
            , {field: 'COST', width: 100, title: '成本(元)'}
            , {field: 'TOTAL_COST', width: 100, title: '总成本(元)'}
            , {field: 'GROSS', width: 100, title: '毛利(万元)'}
            , {field: 'TOTAL_GROSS', width: 120, title: '总毛利(万元)'}
            , {field: 'RATE', width: 100, title: '毛利率%'}
            , {field: 'GWCA026', width: 120, title: '合同交货日期'}
            , {field: 'GWCA058', width: 120, title: '合同下单日期'}
            , {field: 'GWCAORIG_NAME', width: 120, title: '区域'}
            , {field: 'GWCAORIU_NAME', width: 120, title: '合同签订人员'}
            , {field: 'GWCA001_NAME', width: 120, title: '大区域'}
            , {field: 'GWCA024', width: 80, title: '质保期(月)'}
            , {field: 'GWCA026', width: 160, title: '合同签订交货日期'}
            , {field: 'GWCA020', width: 120, title: '支付方式', filterDatas: app.datas_('crm_gwci001_gwca020')}
            , {field: 'GWCA025', width: 100, title: '付款周期',filterDatas:app.datas_('crm_gwci001_gwca025')}
            , {field: 'GWCA059', width: 80, title: '付款方式'}
            , {field: 'GWCA017', width: 120, title: '客户联系人'}
            , {field: 'GWCA018', width: 120, title: '客户联系电话'}
            , {field: 'GWCA007', width: 150, title: '最终客户'}
        ]],
        moduleName = '合同登记表'
    ;

    var Gwcq004 = app.Module.extend({
        init: function () {
            self = this;
            var _searchsArr = app.cloneJSON(cols[0]);
            self._super({
                _tag: 'gwcq004',
                _searchs: [{
                    id: 'gwcq004', tableId: 'gwcq004_table', datas:  _searchsArr.pushArray([
                        {field: 'GWCA003_S', width: 80, title: '招投标否',filterDatas: app.datas_('sys_n_y'),search: 'default', search: 'default',searchOpts: {type:'select'}},
                        {field: 'GWCB002_S', width: 80, title: '车型',search: 'default', searchOpts: {icon:true,readonly:true}},
                        {field: 'GWCA006', width: 80, title: '客户单位',search: 'default', searchOpts: {icon:true,readonly:true}},
                        {field: 'GWCAORIU', width: 80, title: '业务员',search: 'default',searchOpts: {icon:true,readonly:true}},
                        {field: 'GWCAORIG', width: 80, title: '所属部门',search: 'default', searchOpts: {icon: true,readonly:true}},
                    ])
                }],
                _loadTplsFull: [
                    {dom: 'common_open_window', tpl: 'common/_open_window'}
                ]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwcq004_table'),
                    url: g_ctxPath + 'crm/gwcq004/getListData',
                    exportsUrl: g_ctxPath + 'crm/gwcq004/exportsData',
                    exportsName: moduleName + '数据',
                    title: moduleName + '表',
                    method: 'post',
                    id: 'gwcq004_table',
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter', 'exports'],
                    height: 'full-100',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: table_where,
                    done: function (res, curr, count) {

                    }
                });
            });

            var tipsIndex = null;

            $(doc).on('click', function () {
                tipsIndex && layer.close(tipsIndex);
            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwcq004_table', where: table_where});
        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gwcq004',
                    methods: {
                        handleIconClick: function (field) {
                            var vue = this;
                            if (field == 'GWCB002_S') {//车型开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwam001',
                                            columnList: [
                                                {label: '车型', prop: 'GWAM001', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCB002_S = data.GWAM001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择车型',
                                        area: ['600px', '470px']
                                    }
                                });
                            } else if (field == 'GWCA005') {//合同编号
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwca005',
                                            columnList: [
                                                {label: '合同编号', prop: 'GWCA005', width: '150'},
                                                {label: '合同签订组织', prop: 'GWCAMLEGAL_NAME', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCA005 = data.GWCA005;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择合同编号',
                                        area: ['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCA006'){ //客户单位
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_gwak001',
                                            columnList: [
                                                {label: '客户编号', prop: 'GWAK001', width: '200'},
                                                {label: '名称', prop: 'GWAKL004', width: '200'}
                                            ],
                                            searchParam:{
                                                GWBZ002: 'A'
                                            }
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCA006 = data.GWAK001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户单位',
                                        area: ['600px', '470px']
                                    }
                                });
                            }else if(field == 'GWCAORIG'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysorg_id',
                                            columnList: [
                                                {label: '部门ID', prop: 'ID', width: '150'},
                                                {label: '部门名称', prop: 'NAME', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIG = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择所属部门',
                                        area: ['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCAORIU'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysuser_id',
                                            columnList: [{label: 'ID', prop: 'ID', width: '150'},
                                                {label: '名称', prop: 'NAME', width: '150'}]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIU = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择业务员',
                                        area: ['600px', '465px']
                                    }
                                });
                            }
                        }
                    },
                    watch:{

                    },
                    created: function(){

                    }
                }]
            });

            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new Gwcq004();

});
